package apps.softtech.fastmarket.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import apps.softtech.fastmarket.R;
import apps.softtech.fastmarket.model.Product;

public class AdapterSearchResult extends BaseAdapter{

	ArrayList<Product> mProductsList = new ArrayList<Product>();
	LayoutInflater inf;
	Context mContext;
	public AdapterSearchResult(ArrayList<Product> mProductsList,Context mContext){
		this.mContext = mContext;
		this.mProductsList = mProductsList;
		inf = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		return mProductsList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View vi, ViewGroup arg2) {
		if(mProductsList.size()==0||mProductsList==null){
			vi = inf.inflate(R.layout.search_no_result, null);
			return vi;
		}
		ViewHolder vh  = null;
		if(vi==null){
			vh = new ViewHolder();
			vi = inf.inflate(R.layout.item_search_product, null);
			vh.ivProduct = (ImageView)vi.findViewById(R.id.ivSearchResultAvatarProduct);
			vh.tvProductName = (TextView)vi.findViewById(R.id.tvSearchResultNameProduct);
			vi.setTag(vh);
		}else{
			vh = (ViewHolder) vi.getTag();
		}
		vh.ivProduct.setBackgroundResource(R.drawable.ic_launcher);
		vh.tvProductName.setText(""+mProductsList.get(position).getProductId());
		return vi;
	}
	class ViewHolder{
		ImageView ivProduct;
		TextView tvProductName;
	}

}
